﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using System.Xml;
using Genuilder.Extensions.XamlResource;
using Genuilder.Tests;

namespace Genuilder.Extensions.Tests
{
	public class XamlResourceTest
	{
		[Fact]
		public void CanEnumerateResources()
		{
			XamlResourceReader reader = new XamlResourceReader(FilePath("App.xaml"));

			Assert.Equal("Project.App", reader.ResourceHolder.ToString());

			var key = reader.Read();
			Assert.Equal("Style1", key.Key);
			Assert.Equal("Style", key.Type.Name);
			Assert.Equal("http://schemas.microsoft.com/winfx/2006/xaml/presentation", key.Type.Namespace.ToString());
			key = reader.Read();
			Assert.Equal("UriBuilder1", key.Key);
			Assert.Equal("UriBuilder", key.Type.Name);
			var clrNamespace = (XamlCLRNamespace)key.Type.Namespace;
			Assert.Equal("clr-namespace:System;assembly=System", clrNamespace.ToString());
		}

		[Fact]
		public void CanCompileTestProject()
		{
			using(var directory = new TestDirectory().Of(TestData))
			{
				var project = Projects.InDirectory(directory.Path).First();
				var ex = new ExtensibilityFeature();
				ex.AddExtension(new XamlResourceExtension());
				project.InstallFeature(ex);
				project.Save();
				project.Build().AssertBuild();
			}
		}

		string TestData = "../../Data/XamlResource/";
		private string FilePath(string name)
		{
			return TestData + name;
		}
	}
}
